const mysql   = require('mysql');
const dbUtil = require('../util/DBUtil')


  function  login(username,password) {
   const login = 'select * from user where username=? and password=?';
   const params=new Array();
   params.push(username);
   params.push(password);
   sql= mysql.format(login,params);
   console.log('sql:%s',sql);

   return   dbUtil.query(sql);

}

function insert(user){

  let  sql="INSERT INTO `user`(`username`,`password`,`user_type`,`isUsed`) VALUES(?,?,?,?)";
  const params=new Array();

  params.push(user.username);
  if (!user.password) {
     user.password='123456';
  }
  params.push(user.password);
  params.push(user.usertype);
  params.push(user.isused);

  sql= mysql.format(sql,params);
  console.log(sql);
  console.log('sql:s%',sql);

  return   dbUtil.query(sql);

}


module.exports ={
  login:login,
  insert:insert
}


